package com.itheima.controller;

import com.itheima.pojo.Dept;
import com.itheima.pojo.Result;
import com.itheima.service.DeptSetvice;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.lang.annotation.*;
import java.util.List;


//@Slf4j
@RequestMapping("/depts")
@RestController
public class DeptController {

    @Autowired
    private DeptSetvice deptSetvice;
    @GetMapping
   public Result list()
    {
//        log.info("输出全部部门");
        System.out.println("输出所有部门信息");
        List<Dept> deptlist=deptSetvice.findAll();
        return  Result.success(deptlist);
    }
    //参数名一致
    @DeleteMapping
    public  Result delete(Integer id)
    {
//        log.info("根据id删除部门: {}",id);
        System.out.println("根据id删除部门: "+id);
        deptSetvice.deleteById(id);
        return Result.success();
    }
    @PostMapping
    public  Result add(@RequestBody Dept dept)
    {
        System.out.println("新增部门: "+dept);
//        log.info("根据id新增部门: {}",dept);
        deptSetvice.add(dept);

        return Result.success();
    }
    @GetMapping("/{id}")
    public  Result getInfo(@PathVariable Integer id)
    {
//        log.info("根据id查询部门: {}",id);
        System.out.println("根据id来查询部门" + id);
        Dept dept = deptSetvice.getById(id);
        return Result.success(id);
    }
    @PutMapping
    public Result update(@RequestBody Dept dept)
    {
        System.out.println("修改部门: "+ dept);
//        log.info("修改部门: {}",dept);
        deptSetvice.update(dept);
        return Result.success();
    }
}